import type { CloudFilterBarScheme } from '@/components/filter-bar/types'
import type { FilterItem } from '@/components/strong-search'
import { buildColumns } from '@/utils'

export default function useTableColumn() {
  const filterSchemes = computed<CloudFilterBarScheme>(() => {
    const strongSearchOptions: FilterItem[] = [
      {
        maxLength: 19,
        messageModel: 'message',
        message: '规则 ID 格式不正确',
        validate: validateRuleID,
        label: '规则 ID',
        field: 'id'
      },
      {
        label: '规则名称',
        field: 'name_keyword'
      }
    ]
    return {
      widgets: [
        {
          widget: 'select',
          field: 'action',
          placeholder: '请选择执行策略',
          options: [{ label: '全部', value: undefined }, ...executionOptions]
        },
        {
          widget: 'strong-search',
          placeholder: '默认按照规则 ID 搜索',
          options: strongSearchOptions
        }
      ]
    }
  })
  const columns = computed(() =>
    buildColumns([
      {
        width: 48,
        dataIndex: 'sort',
        slotName: 'sort'
      },
      {
        title: '优先级',
        width: 74,
        dataIndex: 'priority'
      },
      {
        title: '规则ID',
        width: 157,
        dataIndex: 'id'
        // format: 'copy'
      },
      {
        title: '规则名称',
        width: 157,
        dataIndex: 'name'
        // format: 'copy'
      },
      {
        title: '执行策略',
        width: 88,
        dataIndex: 'execution',
        slotName: 'execution'
      },
      {
        title: '规则描述',
        width: 240,
        dataIndex: 'condition_description',
        slotName: 'condition_description'
      },
      {
        title: '部署节点',
        width: 88,
        dataIndex: 'node_bind_count',
        slotName: 'node_bind_count'
      },
      {
        title: '状态',
        width: 88,
        dataIndex: 'status',
        slotName: 'status'
      },
      {
        title: '创建时间',
        width: 180,
        dataIndex: 'created_at',
        slotName: 'created_at',
        format: 'date-time',
        sortable: sortableSettings
      },
      {
        title: '操作',
        width: 174,
        slotName: 'action',
        cellClass: 'actions-cell',
        fixed: 'right'
      }
    ])
  )
  return {
    columns,
    filterSchemes
  }
}
